package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

//新增书籍
public class AddQperation implements IOperation{
    @Override
    public void word(BookList bookList) {
        System.out.println("新增书籍");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要添加的书籍的名字:>");
        String name = scanner.nextLine();
        for (int i = 0; i < bookList.getUsedSize(); i++) {
            Book book = bookList.getBook(i);
            if(name.equals(book.getName())){
                System.out.println("已有此书");
                return;
            }
        }
        System.out.println("请输入该书籍的作者:>");
        String author = scanner.nextLine();
        System.out.println("请输入书籍的类型");
        String type = scanner.nextLine();
        System.out.println("请输入书籍的价格:>");
        int price = scanner.nextInt();
        Book book = new Book(name,author,price,type);
        bookList.setBooks(bookList.getUsedSize(),book);
        System.out.println(book);
        System.out.println("添加成功");
        bookList.setUsedSize(bookList.getUsedSize()+1);
    }
}
